{include file="public/layout" /}

<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;min-width:400px;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="box-shadow:none;min-width: 400px;">
    <div class="flexigrid pb30">
        <div class="mDiv">
            <div class="ftitle">
                <h3>可选文档列表</h3>
                <h5>(共{$pager->totalRows}条数据)</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            <form class="navbar-form form-inline" id="searchForm" action="{:url('Special/ajax_node_archives_list')}" method="get" onsubmit="layer_loading('正在处理');">
                {$searchform.hidden|default=''}
                <div class="sDiv">
                    <div class="sDiv2">  
                        <select name="typeid" class="select" style="margin:0px 5px;">
                            <option value="0">--选择栏目--</option>
                            {$arctype_html}
                        </select>
                    </div>
                    <div class="sDiv2">
                        <input type="text" size="30" name="keywords" value="{$Request.param.keywords}" class="qsbox" placeholder="请输入标题">
                        <input type="submit" class="btn" value="搜索">
                        <i class="iconfont e-sousuo"></i>
                    </div>
                </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        <th class="sign w40" axis="col0">
                            <div class="tc"><input type="checkbox" class="checkAll"></div>
                        </th>
                        <th abbr="article_title" axis="col3" class="w40">
                            <div class="tc">ID</div>
                        </th>
                        <th abbr="article_title" axis="col3" class="">
                            <div style="text-align: left; padding-left: 10px;" class="">标题</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w100">
                            <div class="tc">所属栏目</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w60">
                            <div class="tc">浏览量</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w100">
                            <div class="tc">更新时间</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%;">
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <div class="no_row">
                                    <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div>
                                </div>
                            </td>
                        </tr>
                    {else/}
                        {foreach name="list" item="vo" key="k" }
                        <tr>
                            <td class="sign">
                                <div class="tc w40">
                                    <input type="checkbox" name="ids[]" id="input_ids_{$vo.aid}" value="{$vo.aid}" data-title="{$vo.title}">
                                    <textarea class="none" id="ids_{$vo.aid}">{$vo.json_encode_params}</textarea>
                                </div>
                            </td>
                           
                            <td class="sort">
                                <div class="tc w40">
                                    {$vo.aid}
                                </div>
                            </td>
                            <td class="" style="width: 100%;">
                                <div class="tl" style="padding-left: 10px;">
                                    <font style="margin-left: 5px;{eq name="vo.is_b" value="1"} font-weight: bold;{/eq}">{$vo.title}</font>
                                    {assign name='showArcFlagData' value='$vo|showArchivesFlagStr'}
                                    {volist name='$showArcFlagData' id="vo1"}
                                        {eq name='$i' value='1'}<span style="color: red;">[{/eq}
                                        <i style="font-size: 12px;">{$vo1['small_name']}</i>
                                        {eq name='$i' value='$showArcFlagData|count'}]</span>{/eq}
                                    {/volist}
                                </div>
                            </td>
                            <td class="">
                                <div class="w100 tc"><a href="{:url('Special/ajax_node_archives_list', array('typeid'=>$vo['typeid']))}">{$vo.typename|default='<i class="red">数据出错！</i>'}</a></div>
                            </td>
                            <td>
                                <div class="tc w60">
                                    {$vo.click}
                                </div>
                            </td>
                            <td>
                                <div class="w100 tc">
                                    {$vo.update_time|date='Y-m-d',###}
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    {/empty}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                <div class="fbutton checkboxall"><input type="checkbox" class="checkAll"></div>
                <div class="fbuttonr">{include file="public/page" /}</div>
            </div>
            <div style="clear:both"></div>
        </div>
        <!--分页位置-->
    </div>
</div>
<div class="bot3 wm100">
    <div class="item-selected">已选择<font id="selectLength" color="red">0</font>多少条</div>
    <a href="javascript:void(0);" onclick="addAidlist();" class="ncap-btn-big ncap-btn-green"><span>确认</span></a>
    <a class="ncap-btn-big ncap-btn-no" href="javascript:void(0);" onclick="window.parent.layer.closeAll();" title="关闭">关闭</a>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        $('#searchForm select[name=typeid]').change(function(){
            $('#searchForm').submit();
        });
    });

    // 父级页面数据
    var parentNodeAidArr = parent.nodeAidArr;
    var parentNodeAidList = parent.nodeAidList;
    $(function() {
        // 循环加载指定文档为已选中
        for (var i = 0; i < parentNodeAidArr.length; i++) {
            $('#input_ids_' + parentNodeAidArr[i]).prop('checked', true);
        }
        // 判断是否全选
        checkAllLoad();
        // 加载已选文档数
        $('#selectLength').html(parentNodeAidArr.length);

        // 单选操作
        $('input[name*=ids]').click(function() {
            // 判断是否全选
            checkAllLoad();
            // 加载已选节点文档数据
            newNodeAidSelectLoad();
        });

        // 全选操作
        $('input[type=checkbox].checkAll').click(function() {
            $('input[type=checkbox]').prop('checked', this.checked);
            // 加载已选节点文档数据
            newNodeAidSelectLoad();
        });

        // 判断是否全选
        function checkAllLoad() {
            if (parseInt($('input[name*=ids]').length) === parseInt($('input[name*=ids]:checked').length)) {
                $('.checkAll').prop('checked', true);
            } else {
                $('.checkAll').prop('checked', false);
            }
        }

        // 加载已选节点文档数据
        function newNodeAidSelectLoad() {
            var aidArr = [];
            var addList = [];
            $('input[name^=ids]').each(function(i, o) {
                var value = $(o).val();
                if ($(o).is(':checked') && $.inArray(value, aidArr) == -1 && $.inArray(value, parentNodeAidArr) == -1) {
                    // aid处理
                    aidArr.push(value);
                    // 列表处理
                    addList.push({'aid': value, 'title': $(o).data('title')});
                }
            });
            // 合并已选的文档aid数据
            var newAidArr = $.merge(parentNodeAidArr, aidArr);
            // 合并已选的文档列表数据
            var newAddList = $.merge(parentNodeAidList, addList);
            // 去除未选的文档aid和列表数据
            $('input[name^=ids]').each(function(i, o) {
                var value = $(o).val();
                var index = $.inArray(value, newAidArr);
                if (!$(o).is(':checked') && index >= 0) {
                    newAidArr.splice(index, 1);
                    newAddList.splice(index, 1);
                }
            });
            // 加载已选文档数
            $('#selectLength').html(newAidArr.length);
            // 加载到父级页面
            parent.nodeAidSelectLoad(newAidArr, newAddList);
        }
    });

    // 把选定值加到列表
    function addAidlist() {
        if (parentNodeAidArr.length == 0) {
            layer.alert('请至少选择一项', {
                closeBtn: 3,
                move: false,
                title: '提示',
                btnAlign: 'r',
                shade: layer_shade,
                area: ['480px', '190px'],
                success: function () {
                    $(".layui-layer-content").css('text-align', 'left');
                }
            });
            return false;
        }

        parent.selectArticleBack();
        parent.layer.closeAll();
    }
</script>

{include file="public/footer" /}